package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SubjectMapper;
import com.ruoyi.system.domain.Subject;
import com.ruoyi.system.service.ISubjectService;

/**
 * 题库Service业务层处理
 *
 * @author ruoyi
 * @date 2022-11-19
 */
@Service
public class SubjectServiceImpl implements ISubjectService
{
    @Autowired
    private SubjectMapper subjectMapper;

    /**
     * 查询题库
     *
     * @param subjectId 题库主键
     * @return 题库
     */
    @Override
    public Subject selectSubjectBySubjectId(Long subjectId)
    {
        return subjectMapper.selectSubjectBySubjectId(subjectId);
    }

    /**
     * 查询题库列表
     *
     * @param subject 题库
     * @return 题库
     */
    @Override
    public List<Subject> selectSubjectList(Subject subject)
    {
        return subjectMapper.selectSubjectList(subject);
    }

    /**
     * 新增题库
     *
     * @param subject 题库
     * @return 结果
     */
    @Override
    public int insertSubject(Subject subject)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        subject.setMakePerson(loginUser.getUsername());
        return subjectMapper.insertSubject(subject);
    }

    /**
     * 修改题库
     *
     * @param subject 题库
     * @return 结果
     */
    @Override
    public int updateSubject(Subject subject)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        subject.setMakePerson(loginUser.getUsername());
        return subjectMapper.updateSubject(subject);
    }

    /**
     * 批量删除题库
     *
     * @param subjectIds 需要删除的题库主键
     * @return 结果
     */
    @Override
    public int deleteSubjectBySubjectIds(Long[] subjectIds)
    {
        return subjectMapper.deleteSubjectBySubjectIds(subjectIds);
    }

    /**
     * 删除题库信息
     *
     * @param subjectId 题库主键
     * @return 结果
     */
    @Override
    public int deleteSubjectBySubjectId(Long subjectId)
    {
        return subjectMapper.deleteSubjectBySubjectId(subjectId);
    }
}
